package com.mf.controller;

import com.mf.entity.Code;
import com.mf.result.Result;
import com.mf.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
* <p>
    * 股票推荐表 前端控制器
    * </p>
*
* @author mf
* @since 2024-06-01
*/
@RestController
@RequestMapping("/code")
public class CodeController {

    @Resource
    private ICodeService codeService;

    /**
     * 更新股票代码
     */
    @GetMapping("/updateCode")
    public Result<String> updateCode()
    {
        codeService.remove(null);
        List<Code> codeList =  codeService.updateCode();
        if(!codeList.isEmpty()){
            codeService.saveBatch(codeList,500);
        }
        return Result.success("更新成功");
    }

    /**
     * 查询所有股票代码
     */
    @GetMapping("/findAll")
    public Result<List<Code>> findAll(@RequestParam("dm") String dm)
    {
        List<Code> codeList = codeService.findAll(dm);
        return Result.success(codeList);
    }
}
